package hotel.menu.adapter;

import hotel.menu.domain.Food;
import java.util.List;
import com.example.youknow.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class OrderAdapter extends BaseAdapter  {

	private LayoutInflater inflater;
	private List<Food> orders;
	private ViewHolder holder;
	public static int index = -1;

	public OrderAdapter(Context context, List<Food> order) {
		this.orders = order;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return orders.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.order_item, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView
					.findViewById(R.id.order_item_name);
			holder.price = (TextView) convertView
					.findViewById(R.id.order_item_price);
			holder.count = (TextView) convertView
					.findViewById(R.id.order_item_count);
			holder.plus = (RelativeLayout) convertView
					.findViewById(R.id.order_item_puls_rl);
			holder.minus = (RelativeLayout) convertView
					.findViewById(R.id.order_item_minus_rl);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.plus.setVisibility(4);
		holder.minus.setVisibility(4);
		Food detail = orders.get(position);
		holder.name.setText(detail.getDishname());
		holder.count.setText("x" + detail.getCount());
		holder.price.setText(detail.getPrice()+"");
		if (position == index) {
			holder.plus.setVisibility(0);
			holder.minus.setVisibility(0);
		}

		return convertView;
	}

	public static class ViewHolder {
		public RelativeLayout plus, minus;
		public TextView count;
		private TextView name;
		private TextView price;
	}


}
